<template>
	<view class="list-view">
		<view class="top-bar"><uni-navbar :fixed="true" :back="true" color="#fff" title="线索资料详情"></uni-navbar></view>

		<view class="tip-box">
			<view class="tip">
				意见建议数：
				<text class="span">{{ num }}条</text>
			</view>
		</view>

		<view class="list-box" :style="{ background: loading == 'nodata' ? 'none' : '#fff' }">
			<view class="list-info_07" v-for="(item, index) of commentList" :key="item.id">
				<view class="info-avatar"><image class="sub-img" :src="$imagePreview(item.avatar) || '/static/img/theme@2x.png'" mode="aspectFill"></image></view>
				<view class="info-inner">
					<view class="user">
						<text class="name">{{ item.name }}</text>
						<text class="phone">{{ item.phone }}</text>
						<text class="unit">{{ item.unit }}</text>
					</view>
					<u-read-more :showHeight="220" :toggle="true" :shadowStyle="{ backgroundImage: 'none' }">
						<view class="content"><uni-parse :content="item.content"></uni-parse></view>
					</u-read-more>
					<view class="info-btm">
						<view class="time">回复时间：{{ item.replyTime | parseTime('{y}-{m}-{d}') }}</view>
					</view>
				</view>
			</view>
			<u-loadmore :status="loading" />
		</view>

		<u-back-top :scroll-top="scrollTop" top="200"></u-back-top>
	</view>
</template>

<script>
import uniParse from '@/components/uni-parse/parse.vue';
import { mapState } from 'vuex';
export default {
	components: {
		uniParse
	},
	data() {
		return {
			scrollTop: 0,
			num: 0,
			id: '',
			type: '',
			fileList: [],
			commentList: [],
			loading: 'loadmore'
		};
	},
	onLoad(option) {
		this.loadLogin();
		this.id = option.id;
		this.loadData();
	},
	onPullDownRefresh() {
		this.loadData('refresh');
	},
	onReachBottom() {
		if (this.loading == 'loadmore') this.loadData('add');
	},
	onPageScroll(res) {
		this.scrollTop = res.scrollTop;
	},
	computed: {
		...mapState(['userInfo'])
	},
	methods: {
		loadLogin() {
			if (this.userInfo.Authorization) {
				this.userId = this.userInfo.sysUser.id;
				this.clientCode = this.userInfo.sysUser.clientCode;

				this.pageNum = 1;
				this.pageSize = 10;
			} else {
				this.$logout();
			}
		},
		loadData(type = 'add') {
			if (type == 'add' && this.loading == 'loading') {
				return false;
			}
			if (type == 'add' && this.loading == 'nomore') {
				return false;
			}

			this.loading = 'loading';
			if (type != 'add') {
				this.pageNum = 1;
			}
			let url = '/lifayijian/local-legislate-opinions/list';
			let data = {
				pageNum: this.pageNum,
				pageSize: this.pageSize,
				clientCode: this.clientCode,
				currentUserId: this.userId,
				localLegislateId: this.id
			};

			this.$request(url, data, {
				load: true
			}).then((res) => {
				let count = 0;
				if (type != 'add') {
					uni.stopPullDownRefresh();
					this.commentList = [];
				}
				this.loading = this.pageNum < Math.ceil(res.data.total / this.pageSize) ? 'loadmore' : 'nomore';
				this.num = res.data.total;
				this.pageNum = this.pageNum + 1;
				this.commentList = this.commentList.concat(res.data.records);
				this.loaded = true;
				if (this.commentList.length <= 0) {
					this.loading = 'nodata';
				}
			});
		}
	}
};
</script>

<style lang="scss">
.list-box {
	padding: 0 30rpx;
}

.tip-box {
	padding: 20rpx 30rpx;
	background-color: #fff;
}

.tip {
	padding: 20rpx;
	font-size: 18px;
	font-weight: 500;
	color: #999;
	line-height: 50rpx;
	text-align: center;
	background: #f6f7fb;

	.span {
		color: #333;
	}
}
</style>
